<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>猜数字</title>
</head>
<body>
    <div class="parent">
        <div><input type="button" value="重新开始一局新游戏" class="again"></div>
        <div>
            请输入要猜的数字: <input type="text" class="guessNum"> <input type="button" value="猜" class="press">
        </div>
        <div>
            已经猜的次数: <span class="count">0</span>
        </div>
        <div>
            结果: <span class="result"></span>
        </div>
    </div>
    <script>
        let guessNum = document.querySelector('.guessNum');
        let press = document.querySelector('.press');
        let count = document.querySelector('.count');
        let result = document.querySelector('.result');

        let countCount = 0;
        let guessResult = Math.floor(Math.random()*100)+1;
        press.onclick = function(){
            countCount++;
            count.innerHTML = countCount;
            guessNumber = parseInt(guessNum.value);
            if(guessNumber == guessResult){
                result.innerHTML = '猜对了';
                result.style = 'color : red';
            }else if(guessNumber < guessResult){
                result.innerHTML = '猜小了';
                result.style = 'color : blue';
            }else{
                result.innerHTML = '猜大了';
                result.style = 'color : orange';
            }
        }

        let again = document.querySelector('.again');
        again.onclick = function() {
            guessResult = Math.floor(Math.random()*100)+1;
            countCount = 0;
            count.innerHTML = 0;
            guessNum.value = '';
            result.innerHTML ='';
        }
    </script>
</body>
</html>